// component/practice_handle/practice_handle.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    pageIndex:{
      type:Number,
      value:2
    },
    rightCount:{
      type:Number,
      value:-1
    },
    wrongCount:{
      type:Number,
      value: -1
    },
    current:{
      type:Number
    },
    total:{
      type:Number
    },
    subjectList:{
      type:Array
    },
    param:{
      type:Object
    },
    url:{
      type:String
    },
    hideResult:{
      type:Boolean,
      value:false
    }

  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {

    lastSubject: function () {
      if (this.data.current > 0) {
        this.setData({ current: --this.data.current});
        this.triggerEvent('updateCurrent',this.data.current);
      }
    },
    nextSubject: function () {

       
      if (this.data.current == this.data.subjectList.length - 1) {
        
        this.getData(this.data.url,this.data.param);
      }

      if (this.data.current < this.data.subjectList.length - 1) {
        this.setData({ current: ++this.data.current});
        this.triggerEvent('updateCurrent',this.data.current);

      }


    },
    getData: function (url,param) {
      var me = this;
      var params = {
        m: 'rs_anwser',
        pIndex: me.data.pageIndex
      }

      

      params = Object.assign(params,param);
      getApp().util.request({
        url: url,
        data: params,
        success: function (data) {
          console.log(data);

          if (data.data.data.subjectList.length > 0) {

            me.setData({ pageIndex: ++me.data.pageIndex });
            me.triggerEvent('updatePageIndex', me.data.pageIndex);
            me.setData({
              subjectList: me.data.subjectList.concat(data.data.data.subjectList)
            });

            me.triggerEvent('updateSubjectList', me.data.subjectList.concat(data.data.data.subjectList));

          } else {
            wx.showToast({ title: '已经是最后一题了', icon: 'none' });
          }


        }
      })
    }

  },

 
})
